package cn.rkylin.oms.item.vo;

import org.apache.commons.lang.StringUtils;

import cn.rkylin.oms.item.domain.Sku;

/**
 * 平台规格值对象，用于满足前台展示、系统间交互的需要
 *
 * @author wangxing
 * @version 1.0
 * @created 15-2月-2017 16:58:00
 */
public class SkuVO extends Sku {

    private static final String OPERATION_BTN = "<div class=\"btn-group %s\" ><button type=\"button\" data-toggle=\"dropdown\" class=\"btn btn-xs btn-warning dropdown-toggle\">操作 &nbsp;<span class=\"caret\"></span></button><ul role=\"menu\" class=\"dropdown-menu pull-right\"><li><a href=\"#\" onclick=\"operationRelation(this)\" ecSkuId=\"%s\" ecSkuCode=\"%s\">关联系统商品</a></li><li><a href=\"#\" onclick=\"operationCancelRelation(this)\" ecSkuId=\"%s\">取消关联</a></li><li><a href=\"#\" onclick=\"operationGroupRelation(this)\" ecSkuId=\"%s\" ecSkuCode=\"%s\" ecSkuName=\"%s\" ecItemId=\"%s\">组合商品设置</a></li><li><a href=\"#\" onclick=\"operationSynchStock(this)\" ecSkuId=\"%s\">库存同步</a></li></div>";
//    private static String SHOWINDEX = "1040";

    /**
     * 序列化id
     */
    private static final long serialVersionUID = 1197685522201484879L;

    private String isGroupShow;

    private String operation;

    /**
     * 搜索条件
     */
    private String searchCondition;

    /**
     * orderBy子句
     */
    private String orderBy;
    
    /**
     * 转换下拉按钮的方向(取值“”，“dropup”)
     */
    private String reversePosition;

    public String getOrderBy() {
        // 此字段需要防止sql注入
        return orderBy == null ? null : orderBy.replaceAll(".*([';]+|(--)+).*", " ");
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    public String getSearchCondition() {
        return searchCondition;
    }

    public void setSearchCondition(String searchCondition) {
        this.searchCondition = searchCondition;
    }

    public String getOperation() {
        StringBuffer opButton = new StringBuffer();

        opButton.append(String.format(OPERATION_BTN, getReversePosition(),  getEcSkuId(), getEcSkuCode(), getEcSkuId(), getEcSkuId(), getEcSkuCode(),
                getEcSkuName(), getEcItemId(), getEcSkuId()));
        opButton.append("&nbsp;");
//        SHOWINDEX = String.valueOf(Integer.valueOf(SHOWINDEX).intValue() - 1);

        return opButton.toString();
    }

    public String getIsGroupShow() {
        if ("y".equals(this.getIsGroup())) {
            isGroupShow = "是";
        } else {
            isGroupShow = "否";
        }
        return isGroupShow;
    }

    public void setIsGroupShow(String isGroupShow) {
        this.isGroupShow = isGroupShow;
    }

    public String getReversePosition() {
        return StringUtils.isEmpty(reversePosition) ? "" : reversePosition;
    }

    public void setReversePosition(String reversePosition) {
        this.reversePosition = reversePosition;
    }

    // public void setOperation(String operation) {
    // StringBuffer opButton = new StringBuffer();
    //
    // opButton.append(String.format(OPERATION_BTN_RELATION, getEcSkuId()));
    // opButton.append("&nbsp;");
    // opButton.append(String.format(OPERATION_BTN_CANCEL_RELATION,
    // getEcSkuId()));
    //
    // this.operation = opButton.toString();
    // }
}